package cn.itcast.order.web;

import cn.itcast.order.service.QuartzService;
import org.quartz.SchedulerException;
import org.quartz.TriggerKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/quartzStop")
public class QuartzStopController {

    @Autowired
    private QuartzService quartzService;

    @PostMapping("/stop-trigger")
    public ResponseEntity<String> stopTrigger(@RequestParam String triggerName, @RequestParam String triggerGroup) {
        TriggerKey triggerKey = new TriggerKey(triggerName, triggerGroup);
        try {
            quartzService.stopTrigger(triggerKey);
            return ResponseEntity.ok("触发器已停止");
        } catch (SchedulerException e) {
            // 处理异常，例如记录日志或返回错误响应
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("停止触发器时出错");
        }
    }
}